#pragma once

#include<iostream>
#include<pthread.h>


class Mutex
{
public:
    Mutex(pthread_mutex_t* pmtx)
    :pmtx_(pmtx)
    {}

    void lock()
    {
        pthread_mutex_lock(pmtx_);
    }

    void unlock()
    {
        pthread_mutex_unlock(pmtx_);
    }
private:
    pthread_mutex_t *pmtx_;
};

class lockGuard
{
public:
    lockGuard(Mutex mtx)
    :mtx_(mtx)
    {
        std::cout<<"加锁---"<<std::endl;
        mtx_.lock();
    }

    ~lockGuard()
    {
        std::cout<<"解锁"<<std::endl;
        mtx_.unlock();
    }
private:
    Mutex mtx_;
};